package com.android.act.setting;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.android.R;
import com.android.common.Action;

public class SystemInfo extends Activity {
	Action acion;
	 
	private TextView topbar_title;
	private List<Map<String, Object>> list = null;
	private SimpleAdapter adapter1 = null;
	private TextView settingText = null;
	private ListView setting_list_item = null;
	private Intent intent; 
	 
	String str = "";
	TelephonyManager tm;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting_systeminfo);
		
		 
		acion = new Action(SystemInfo.this);
		 
		
		topbar_title = (TextView) findViewById(R.id.titlebar_name);
		topbar_title.setText("系统信息");

		initView();

	}

	private void initView() {
		// settingText =(TextView)findViewById(R.id.setting_text_item);
		setMap();
		adapter1 = new SimpleAdapter(this, list, R.layout.setting_inforow,
				new String[] { "name", "desc" }, new int[] { R.id.sysinfo_name,
						R.id.sysinfo_desc });

		setting_list_item = (ListView) findViewById(R.id.itemlist);
		setting_list_item.setAdapter(adapter1);
		setting_list_item.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int positon, long arg3) {

			}
		});
	}

	public void setMap() {

		list = new ArrayList<Map<String, Object>>();
		Map<String, Object> map = new HashMap<String, Object>();

		map = new HashMap<String, Object>();
		map.put("id", 1);
		map.put("name", "网络状态");
		map.put("desc", getCallState());
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("id", 2);
		map.put("name", "手机方位");
		map.put("desc", getCellLocation());
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("id",3);
		map.put("name", "设备序号");
		map.put("desc",getDeviceId() );
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("id", 4);
		map.put("name", "软件版本");
		map.put("desc",  getDeviceSoftwareVersion());
		list.add(map);

		map = new HashMap<String, Object>();
		map.put("id",5);
		map.put("name", "网络提供");
		map.put("desc", getSimOperatorName());
		list.add(map);
		map = new HashMap<String, Object>();
		map.put("id",5);
		map.put("name", "SIM序号");
		map.put("desc",  getSimSerialNumber());
		list.add(map);
	}

	public String getCallState() {
		/*
		 * 电话状态： 1.tm.CALL_STATE_IDLE=0 无活动 2.tm.CALL_STATE_RINGING=1 响铃
		 * 3.tm.CALL_STATE_OFFHOOK=2 摘机
		 */
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);
		return String.valueOf(tm.getCallState());// int
	}



	public String getCellLocation() {// str = "电话状态：" + tm.getCallState();
		/*
		 * 电话方位：
		 */
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);
		return String.valueOf(tm.getCellLocation());// int
	}

	public String getDeviceId() {
		/*
		 * 唯一的设备ID： GSM手机的 IMEI 和 CDMA手机的 MEID. Return null if device ID is not
		 * available.
		 */
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);
	
		str = "" + tm.getDeviceId();
		return str;
	}

	public String getDeviceSoftwareVersion() {
		/*
		 * 唯一的设备ID： GSM手机的 IMEI 和 CDMA手机的 MEID. Return null if device ID is not
		 * available.
		 */
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);
		
		str = ""+ tm.getDeviceSoftwareVersion();// String
		return str;
	}

	public String getNetworkOperatorName() {
		/*
		 * 按照字母次序的current registered operator(当前已注册的用户)的名字 注意：仅当用户已在网络注册时有效。
		 * 在CDMA网络中结果也许不可靠。
		 */
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);

		str = "" + tm.getNetworkOperatorName();// String
		return str;
	}

	public String getSimOperatorName() {
		/*
		 * 按照字母次序的current registered operator(当前已注册的用户)的名字 注意：仅当用户已在网络注册时有效。
		 * 在CDMA网络中结果也许不可靠。
		 */
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);
		str = "" + tm.getSimOperatorName();// String
		return str;
	}

	public String getSimSerialNumber() {
		/*
		 * SIM卡的序列号： 需要权限：READ_PHONE_STATE
		 */
		
		tm = (TelephonyManager) this
				.getSystemService(TELEPHONY_SERVICE);
		str = "" + tm.getSimSerialNumber();// String
		return str;
	}

}
